home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / turbovis / dlgds411.zip / CPPSRC2.CPP < prev    next >
C/C++ Source or Header  |  1993-12-12  |  19KB  |  746 lines

  1. /*Substitutions and fills in file, cppskel.dat
  2.  
  3.   Area Fills
  4.   @ZZ0    Form the dialog in constructor
  5.   @ZZ1    Defined Control Names in Object Def.
  6.   @ZZ2    Data struct def
  7.   @ZZ3    Variable names in 'read'
  8.   @ZZ4    Variable names in 'write'
  9.   @ZZ5    Ancestor constructor call
  10.   @ZZ6    Uses_ stuff
  11.   @ZZ7    include of tcolortx.h, tinplong.h
  12.   @ZZ8    Links
  13.  
  14.   Substitutions
  15.   @XX1    Dialog's Symbol   (as  TMyDialog)
  16.   @XX2    Dialog's ancestor (usually TDialog)
  17.   @XX3    Dialog's registration TStreamRec (as RMyDialog)
  18.   @XX4    Filename (upper case)
  19.   @XX5    Filename (lower case)
  20. */
  21.  
  22. #define Uses_TStringCollection
  23. #include <tv.h>
  24. #include <stdlib.h>
  25. #include <dos.h>
  26. #include <dir.h>
  27. #include <fcntl.h>
  28. #include <string.h>
  29. #include <iostream.h>
  30. #include <fstream.h>
  31. #include <stdio.h>
  32. #include "readscpt.h"
  33.  
  34. ofstream outf;
  35. ifstream data;
  36. #define BIG 300
  37. char s[BIG], upperName[MAXFILE], lowerName[MAXFILE];
  38. Boolean needcontrol1 = False;
  39.  
  40. char* quoted(const char* s)
  41. //if the first char of s is '@', assumes a variable wanted and strips the '@'
  42. //else returns a double quoted string or 0 for empty string
  43. {
  44.  static char q[300];
  45.  if (s[0] == '@')
  46.    {strcpy(q, &s[1]);
  47.     return q;
  48.    }
  49.  strcpy(q, "\"");   //the first quote in place
  50.  if (*s == '\0' || !s) return "0";
  51.  strcat(q, s);
  52.  short l = strlen(q);
  53.  q[l] = '\"';
  54.  q[l+1] = '\0';
  55.  return q;
  56. }
  57.  
  58. void aField(ViewObj *P, char* fieldtype)
  59. {
  60.  outf << "  " << fieldtype << " " << P->FieldName << ";   //" << P->Obj <<endl;
  61. }
  62. void aVar(ViewObj *P)
  63. {
  64.  if (strcmp(P->VarName, "control") != 0)
  65.    outf << "    " << P->Obj << " *" << P->VarName << ";\n";
  66. }
  67.  
  68. //the following extend the ViewObj struct's to also write the code
  69. struct DialogWriteObj : DialogObj {
  70.      virtual void writeCode();
  71.      };
  72.  
  73. struct ButtonWriteObj : ButtonObj {
  74.      virtual void writeCode();
  75.      virtual void writeVars() {aVar(this);};
  76.      };
  77.  
  78. struct InputLongWriteObj : InputLongObj {
  79.      virtual void writeCode();
  80.      virtual void writeFields() {aField(this, "long");} ;
  81.      virtual void writeVars() {aVar(this);};
  82.      };
  83. struct LabelWriteObj : LabelObj {
  84.      virtual void writeCode();
  85.      };
  86. struct HistoryWriteObj : HistoryObj {
  87.      virtual void writeCode();
  88.      };
  89. struct InputLineWriteObj : InputLineObj {
  90.      virtual void writeCode();
  91.      virtual void writeFields();
  92.      virtual void writeVars() {aVar(this);};
  93.      };
  94. struct ClusterWriteObj : ClusterObj {
  95.      virtual void writeCode();
  96.      virtual void writeFields() {aField(this, "ushort");} ;
  97.      virtual void writeVars() {aVar(this);};
  98.      };
  99. struct ListBoxWriteObj : ListBoxObj {
  100.      virtual void writeCode();
  101.      virtual void writeFields() {aField(this, "TListBoxRec");} ;
  102.      virtual void writeVars() {aVar(this);};
  103.      };
  104. struct ScrollBarWriteObj : ScrollBarObj {
  105.      virtual void writeCode();
  106.      virtual void writeVars();
  107.      };
  108. struct MemoWriteObj : MemoObj {
  109.      virtual void writeCode();
  110.      virtual void writeFields();
  111.      virtual void writeVars() {aVar(this);};
  112.      };
  113. struct StaticTextWriteObj : StaticTextObj {
  114.      virtual void writeCode();
  115.      virtual void writeVars() {aVar(this);};
  116.      };
  117. struct ColoredTextWriteObj : ColoredTextObj {
  118.      virtual void writeCode();
  119.      virtual void writeVars() {aVar(this);};
  120.      };
  121.  
  122.  
  123.  
  124. //now that we know the final extensions of ViewObj, we can write the
  125. //getKind function
  126. ViewObj *getKind(recType Kind)
  127. { ViewObj *P;
  128.   switch (Kind) {
  129.       case Dlg : P = new DialogWriteObj(); break;
  130.       case Button : P = new ButtonWriteObj(); break;
  131.       case InputL : P = new InputLineWriteObj(); break;
  132.       case Labl : P = new LabelWriteObj();  break;
  133.       case Histry : P = new HistoryWriteObj(); break;
  134.       case ILong : P = new InputLongWriteObj(); break;
  135.       case CheckB: P = new ClusterWriteObj(); break;
  136.       case RadioB: P = new ClusterWriteObj(); break;
  137.       case MultiCB: P = new MultiCheckBoxObj(); break;
  138.       case ListB: P = new ListBoxWriteObj(); break;
  139.       case ScrollB :  P = new ScrollBarWriteObj(); break;
  140.       case Memo: P = new MemoWriteObj(); break;
  141.       case SText: P = new StaticTextWriteObj(); break;
  142.       case CText : P = new ColoredTextWriteObj(); break;
  143.       default : P = 0; break;
  144.       }
  145. return P;
  146. }
  147.  
  148. char * getWinFlagWords(ushort w, char *s)
  149. //given the set bits return names in 'or' form
  150. {
  151.  static char *flagArray[4] =  {
  152.     "wfMove", "wfGrow", "wfClose", "wfZoom"};
  153.  s[0] = '\0';
  154.  for (int i = 0; i <= 3; i++) {
  155.    if ((w & 1) == 1 && flagArray[i][0] != '\0')
  156.      strcat(strcat(s, flagArray[i]), " | ");
  157.    w >>= 1;
  158.    }
  159.  int l = strlen(s);
  160.  if (l > 4)
  161.     s[l-3] = '\0';   //remove last " | "
  162.  return s;
  163. }
  164.  
  165. char * getEventWords(ushort w, char *s)
  166. //given the set bits return names in 'or' form
  167. {
  168.  static char *flagArray[16] =  {
  169.         "evMouseDown", "evMouseUp", "evMouseMove", "evMouseAuto",
  170.     "evKeyDown", "0x20", "0x40", "0x80", "evCommand", "evBroadcast",
  171.     "0x400", "0x800", "0x1000", "0x2000", "0x4000", "0x8000"};
  172.  s[0] = '\0';
  173.  for (int i = 0; i <= 15; i++) {
  174.    if ((w & 1) == 1 && flagArray[i][0] != '\0')
  175.      strcat(strcat(s, flagArray[i]), " | ");
  176.    w >>= 1;
  177.    }
  178.  int l = strlen(s);
  179.  if (l > 4)
  180.     s[l-3] = '\0';   //remove last " | "
  181.  return s;
  182. }
  183.  
  184. char * getOptionWords(ushort w, char *s)
  185. //given the set bits return names in 'or' form
  186. {
  187.  static char *flagArray[16] =  {
  188.         "ofSelectable", "ofTopSelect", "ofFirstClick", "ofFramed",
  189.         "ofPreProcess", "ofPostProcess", "ofBuffered", "ofTileable",
  190.         "ofCenterX", "ofCenterY", "ofValidate", "0x800", "0x1000",
  191.         "0x2000", "0x4000", "ofShoehorn"};
  192.  s[0] = '\0';
  193.  for (int i = 0; i <= 15; i++) {
  194.    if ((w & 1) == 1 && flagArray[i][0] != '\0')
  195.      strcat(strcat(s, flagArray[i]), " | ");
  196.    w >>= 1;
  197.    }
  198.  int l = strlen(s);
  199.  if (l > 4)
  200.     s[l-3] = '\0';   //remove last " | "
  201.  return s;
  202. }
  203.  
  204. short bitCount(ushort w) //numbers of set bits in the word
  205. {
  206.  short count = 0;
  207.  for (int i = 0; i <= 15; i++)  {
  208.     if ((w & 1) == 1)
  209.        count++;
  210.     w >>= 1;
  211.     }
  212. return count;
  213. }
  214.  
  215. void doBitOutput(const char* var, const char* pre, ushort actual,
  216.                        ushort defaul, char* (func)(ushort w, char* s))
  217. //output something like "foo->options |= ofSelectable or ofFramed;"
  218. //and/or "foo-> options &= ofTopSelect;"
  219. //actual is the bits set and defaul are the default settings
  220. //it's known that actual and defaul are not equal on entry
  221. {
  222.  char s[100];
  223.  ushort NOTs, ORs, diff ;
  224.  diff = actual ^ defaul;  //the bits that are different
  225.  if (bitCount(diff) > 5) { //this is too complex--output hex number
  226.    outf << " " << var << pre << " = 0x" << hex << actual << dec <<";\n";
  227.    return;
  228.    }
  229.  NOTs = diff & defaul;  //the bits not in defaul
  230.  ORs = diff & actual;    //the extra bits in actual
  231.  s[0] = '\0';
  232.  if (NOTs != 0) {
  233.    outf << " " << var <<pre;
  234.    if (bitCount(NOTs) == 1)
  235.      outf << " &= ~" << func(NOTs, s) << ";\n";
  236.    else
  237.      outf << " &= ~(" << func(NOTs, s) << ");\n";
  238.    }
  239.  s[0] = '\0';
  240.  if (ORs != 0)
  241.    outf << " " << var << pre << " |= " << func(ORs, s) << ";\n";
  242. }
  243.  
  244. void doTRect(ViewObj *P)
  245. {
  246. outf << "(TRect(" << P->X1 << ", " << P->Y1 << ", "
  247.      << P->X2 << ", " << P->Y2 << ")";
  248. }
  249.  
  250. void insertControl(const char *Name)
  251. {
  252.  outf <<  " insert(" << Name << ");\n\n";
  253. }
  254.  
  255. void doOpEvent(ViewObj *P)
  256. {if (P->DefEvMsk != P->EvMsk)
  257.    doBitOutput(P->VarName, "->eventMask", P->EvMsk, P->DefEvMsk, getEventWords);
  258.  
  259. if (P->DefOptns != P->Optns)
  260.    doBitOutput(P->VarName, "->options", P->Optns, P->DefOptns, getOptionWords);
  261.  
  262. }
  263.  
  264. void writeHelpCtx(char * VarName, char* H, ushort Ctx)
  265. {
  266. if (*H != '\0') {
  267.   if (strcmp(H, "hcNoContext")) {
  268.     outf << " " << VarName << "->helpCtx = " << H << ";\n";
  269.     }
  270.   }
  271. else if (Ctx != 0) {
  272.     outf << " " << VarName << "->helpCtx = " << Ctx << ";\n";
  273.     }
  274. }
  275.  
  276. void start(ViewObj *P)
  277. {
  278.   outf << " " << P->VarName << " = new " << P->Obj;
  279.   doTRect(P);
  280. }
  281.  
  282. void finish(ViewObj *P)
  283. {
  284.  writeHelpCtx(P->VarName, P->HelpCtxSym, P->HCtx);
  285.  doOpEv